<?php namespace Admin\Controller;

//审核控制器
class CheckController extends CommonController{
	//存放模型对象
	private $companyModel;
	public function __auto(){
		$this->companyModel=new \Common\Model\Company;
	}

	//待审核页面
	public function index(){
		//分页
		$Page=Page::row(4)->make($this->companyModel->leftJoin('user','uid','=','lg_user_uid')->where("company_status=1")->count());
		View::with('Page',$Page);
		//筛选待审核公司
		$companyData=$this->companyModel
					->leftJoin('user','uid','=','lg_user_uid')
					->where("company_status=1")
					->orderBy('sendtime','DESC')
					->limit(Page::limit())
					->get();
		View::with('companyData',$companyData)->make();
	}

	//已通过页面
	public function pass(){
		//分页
		$Page=Page::row(4)->make($this->companyModel->leftJoin('user','uid','=','lg_user_uid')->where("company_status=2")->count());
		View::with('Page',$Page);
		//筛选已通过公司
		$companyData=$this->companyModel
					->leftJoin('user','uid','=','lg_user_uid')
					->where("company_status=2")
					->orderBy('sendtime','ASC')
					->limit(Page::limit())
					->get();
		View::with('companyData',$companyData)->make();
	}

	//给予通过方法
	public function open(){
		//获得公司id
		$gsid=Q('get.gsid',0,'intval');
		//获得user表对应id
		$uid=$this->companyModel->where("gsid=$gsid")->pluck('lg_user_uid');
		//更新状态
		Db::table('user')->where("uid=$uid")->update(['company_status'=>2]);
		View::success('成功通过审核提交','pass');
	}

	//不给予通过/过期重审
	public function deny(){
		//获得公司id
		$gsid=Q('get.gsid',0,'intval');
		//获得user表对应id
		$uid=$this->companyModel->where("gsid=$gsid")->pluck('lg_user_uid');
		//更新状态
		Db::table('user')->where("uid=$uid")->update(['company_status'=>3]);
		View::success('成功驳回审核提交','index');
	}

	//查看审核信息
	public function examine(){
		//获得公司id
		$gsid=Q('get.gsid',0,'intval');
		$again=Q('get.again',0,'intval');
		//获得审核信息
		$data=$this->companyModel->where("gsid=$gsid")->find();
		$data['again']=$again;
		//分配数据并显示模板
		View::with('data',$data)->make();
	}

}